package edu.towson.greenteam;


import junit.framework.Assert;

import org.junit.Test;

import edu.towson.greenteam.comment.Comment;
import edu.towson.greenteam.menu.MenuItem;
import edu.towson.greenteam.menu.Price;
import edu.towson.greenteam.order.Order;
import edu.towson.greenteam.tab.Tab;
import edu.towson.greenteam.table.Table;
import edu.towson.greenteam.offer.Offer;

public class InformationAggregatorTest {

	@Test
	public void testTables() {
		InformationAggregator ia = new InformationAggregator();
		//add tables
		ia.getTables().add(2, false, 1);
		ia.getTables().add(2, true, 2);
		ia.getTables().add(4, true, 3);
		ia.getTables().add(4, true, 4);
		ia.getTables().add(6, true, 5);
		ia.getTables().add(6, false, 6);
		
		Assert.assertEquals(ia.getTables().get(0).isOccupied(), false);
		Assert.assertEquals(ia.getTables().get(5).isOccupied(), false);
		
		Iterator<Table> tnoItr = ia.getTables().createTblNotOccupiedItr();
		int count = 0;
		while (tnoItr.hasNext())
		{
			Table t = tnoItr.next();
			if (t != null)
			{
				Assert.assertEquals(t.isOccupied(), false);
				count++;
			}
		}
		Assert.assertEquals(count, 2);
	}
	
	@Test
	public void testMenu() {
		InformationAggregator ia = new InformationAggregator();
		MenuItem salad = new MenuItem("salad", new Price(1.0f), 5);
		MenuItem soup = new MenuItem("soup", new Price(1.0f), 5);
		MenuItem sandwhich = new MenuItem("sandwhich", new Price(1.0f), 5);
		MenuItem goat = new MenuItem("goat", new Price(1.0f), 5);
		ia.getMenu().add(salad);
		ia.getMenu().add(soup);
		ia.getMenu().add(sandwhich);
		ia.getMenu().add(goat);
		
		Iterator<MenuItem> miItr = ia.getMenu().getMenuPriceItr(1.0f);
		
		while (miItr.hasNext())
		{
			MenuItem mi = miItr.next();
			Assert.assertEquals(mi.getPrice().getCurrentPrice(), 1.0f);
		}

		Assert.assertEquals(ia.getMenu().contains(salad), true);
		ia.getMenu().remove(salad);
		Assert.assertEquals(ia.getMenu().contains(salad), false);
		ia.getMenu().add(salad);
		Assert.assertEquals(ia.getMenu().contains(salad), true);
	}

	@Test
	public void testComment() {
		InformationAggregator ia = new InformationAggregator();
		ia.getCustComments().add("good", "good");
		ia.getCustComments().add("bad", "bad");
		ia.getCustComments().add("fair", "fair");
		ia.getCustComments().add("average", "average");
		
		//test to make sure all four are unreviewed
		Iterator<Comment> commentItr = ia.getCustComments().createCCNotReviewedItr();
		int count = 0;
		while(commentItr.hasNext())
		{
			Comment currentComment = commentItr.next();
			Assert.assertEquals(currentComment.isReviewed(), false);
			count++;
		}
		Assert.assertEquals(count, 4);
		
		//set one to reviewed and make sure their is one less
		ia.getCustComments().remove(ia.getCustComments().get(1));
		Iterator<Comment> commentItr2 = ia.getCustComments().createCCNotReviewedItr();
	
		count = 0;
		while(commentItr2.hasNext())
		{
			Comment currentComment = commentItr2.next();
			Assert.assertEquals(currentComment.isVisible(), false);
			count++;
		}
		Assert.assertEquals(count, 3);	
	}
	
	@Test
	public void testTab() {
		InformationAggregator ia = new InformationAggregator();
		ia.getTabs().add(1);
		ia.getTabs().add(2);
		ia.getTabs().add(3);
		ia.getTabs().add(4);
		
		Iterator<Tab> tabAllItr = ia.getTabs().createTabAllItr(ia.getTabs());

		int count = 0;
		while (tabAllItr.hasNext())
		{
			Tab currentTab = tabAllItr.next();
			Assert.assertEquals(currentTab.getDiscount(), 0f);
			count++;
		}
		Assert.assertEquals(count, 4);
		
	}
	
	@Test
	public void testOrder() {
		InformationAggregator ia = new InformationAggregator();
		ia.getOrders().add(1, "salad", 1f, new Table());
		ia.getOrders().add(2, "soup", 2f, new Table());
		ia.getOrders().add(3, "dinner", 3f, new Table());
		ia.getOrders().add(4, "desert", 4f, new Table());
		
		Iterator<Order> orderAllItr = ia.getOrders().createOrderAllItr(ia.getOrders());
		int count = 0;
		while (orderAllItr.hasNext())
		{
			orderAllItr.next();
			count++;
		}
		Assert.assertEquals(count, 4);
		
	}
	
	@Test
	public void testOffer()	{
		InformationAggregator ia = new InformationAggregator();
		ia.getOffers().add(new Offer(1, "ten percent", "", 10, 10));
		ia.getOffers().add(new Offer(2, "twenty percent", "", 20, 20));
		ia.getOffers().add(new Offer(3, "thirty percent", "", 30, 30));
		ia.getOffers().add(new Offer(4, "fourty percent", "", 40, 40));
		
		Iterator<Offer> offerItr = ia.getOffers().getItr();
		
		int count = 0;
		while (offerItr.hasNext())
		{
			Offer offer = offerItr.next();
			if (offer.getId() == 4)
			{
				ia.getOffers().remove(offer);
			}
			count++;
		}
		Assert.assertEquals(count, 4);
		
		
		Iterator<Offer> offerItr2 = ia.getOffers().getItr();
		count = 0;
		while (offerItr2.hasNext())
		{
			offerItr2.next();
			count++;
		}
		Assert.assertEquals(count, 3);
		
	}
	
}
